package controllerLayer;
import java.util.List;

import modelLayer.*;
import BDLayer.*;

public class ProductController {

	private IFDBProduct productDB = new DBProduct();	
	
	
	
	
	//interaction 4 find product
	public List<Product> getAllProduct(){
		return productDB.getAllProduct(false);
	}
	
	
	public Product getProductByID(String prID){
		return productDB.findProductByID(prID, false);
	}
	
	
	//createProduct and insertProduct
		public boolean insertProduct(String productID, String colorCode, Store storeObj, int personID){
			boolean ok = false;
			try{
				Product prObj = new Product();
				prObj.setProductID(productID);
				prObj.setColorCode(colorCode);
				prObj.setStore(storeObj);
				Person person = new StoreEmployee();
				person.setId(personID);
				prObj.setpObj(person);
				if(insertProduct(prObj) == 1){
					ok = true;
				}
				
			}
			catch(Exception e){
				p("Exception creating product Object in PalletController : "+e);
			}
			return ok;
		}
		
		//insert Product in DB
		public int insertProduct(Product prObj){
			int rc = -1;
			try {
				rc = productDB.insertProduct(prObj, true);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				p("Exception insert Product :"+e);
			}
			return rc;
		}
		
		
		public int deleteProduct(String prID){
			Product pObj = getProductByID(prID);
			return productDB.deleteProduct(pObj);		
		}
	
	public void p(String e){System.out.println(e);}
}
